local meta = FindMetaTable("Player")
local emeta  = FindMetaTable("Entity")

require "chatcommand"
--[[
	Flags
		Whitelist system
]]--

	--[[Available Flags:
			Jobs;
				"gangster"
				"cop"
				"chief"
				"cook"
			Administration;
				"a"		- Can give armor to anyone
				"a2"	- Can take armor to anyone
				"b"		- Can give health to anyone
				"c"		- Can slap players (themselves too) worth 25% of their health
				"d"		- Can give players (themselves too) money
				"d2"	- Can take players (themselves too) money
				"e"		- Can slay players (themselves too)
				"f"		- Can kick players (cant kick themselves)
				"g"		- Can noclip themselves
				"z"		- Has all flags, and is allowed to give anybody flags
			Everyone;
				"p"		- Is allowed to buy props
				"q"		- Can spawn with physgun
				"r"		- Can spawn with toolgun
				"j"		- Can change their roleplay name
	]]--
	-- I am NOT using the above flags anymore, these are only for jobs now.
function meta:GiveFlag( flag )
	table.insert(self.LusionData.Players.Flags, flag)
	self:SetPData("lusion_"..flag, "1")
	self:SetNWString("lusion_"..flag, "1")
end

function meta:TakeFlag( flag )
	table.remove(self.LusionData.Players.Flags, flag)
	self:SetPData("lusion_"..flag, "0")
	self:SetNWString("lusion_"..flag, "0")
end

function meta:HasFlag( flag )
	return (self:GetPData("lusion_"..flag) == "1")
end

hook.Add("PlayerInitialSpawn", "PlayerGiveFlagClientsidePart1", function(pl)
	for k,v in pairs(Lusion_Teams) do
		if v.needsFlag then
			if not pl:HasFlag( v.idName ) then
				pl:SetNWString("lusion_".. v.idName, "0")
			else
				pl:SetNWString("lusion_".. v.idName, "1")
			end
		else
			pl:SetNWString("lusion_".. v.idName, "1")	-- Didn't think this would be needed, but oh well
		end
	end
end)


--[[ 
	Abilities
		Giving, removing, and checking abilities. Used in jobs and pretty much everywhere.
]]--
function meta:GiveSkill( skill, amount )
	if not skill then return end
	if not amount then amount = "1" end
	
	self:SetPData("lusion_skill_".. skill, self:GetPData("lusion_skill_".. skill) + tostring(amount))
end
function meta:AddSkill( skill, amount )
	self:GiveSkill( skill, amount )
end
function meta:RemoveSkill( skill, amount )
	if not skill then return end
	if not amount then amount = "1" end
	
	self:SetPData("lusion_skill_".. skill, self:GetPData("lusion_skill_".. skill) + tostring(amount))
end
function meta:TakeSkill( skill, amount )
	self:RemoveSkill( skill, amount )
end
function meta:HasSkill( skill, amount )
	if not skill then return end
	if not amount then amount = "1" end
	if self:GetPData("lusion_skill_".. skill) >= amount then
		return true
	else
		return false
	end
end
function meta:GetSkill( skill )
	if not skill then return end
	
	return self:GetPData("lusion_skill_".. skill)
end

--[[
	Doors
		Door meta serverside, and door commands.
]]--


--[[
	Player notes (Notifications)
		Send a player a notification like Sandbox does it.
]]--
function meta:PlayerNote( str, length )
	if not (str or length) then return end
	umsg.Start("PlayerNotify", self)
		umsg.String(str)
		umsg.Short(length)
	umsg.End()
end
--[[function meta:PlayerChat( str, color )	-- Only supports one color at the moment.
	if not ( str or color ) then return end
	umsg.Start("PlayerChatColor", self)
		umsg.String( tostring(color.r) )
		umsg.String( tostring(color.g) )
		umsg.String( tostring(color.b) )
		
		umsg.String(str)
	umsg.End()
end]]--